# 装饰器，将方法的错误 用异常的方式抛出
from PyQt5.QtWidgets import QMessageBox


def handle_exceptions(func):
    def wrapper(*args, **kwargs):
        try:
            return func(*args, **kwargs)
        except Exception as e:
            print(f"An error occurred: {e}")
            show_error_dialog(e)  # 使用辅助函数显示错误对话框
    return wrapper

def show_error_dialog(error_message):
    QMessageBox.critical(None, "Error", "An error occurred:\n" + str(error_message))